package com.xonro.common.histrans.zz.biz.base;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.util.UUIDGener;
import com.actionsoft.sdk.local.SDK;
import com.xonro.common.histrans.base.consts.DrpConst;
import com.xonro.common.histrans.base.ctx.BOCreateData;
import com.xonro.common.histrans.base.ctx.HistoryTransContext;
import com.xonro.common.histrans.base.model.HistoryTransLogModel;
import com.xonro.common.histrans.sfeg.biz.common.SfegRecordTransBiz;
import com.xonro.common.histrans.zz.biz.common.DrpRecordTransBiz;
import com.xonro.common.histrans.zz.ctx.DrpProcessCreateContext;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

public class ProcessTeamGroupBiz extends DrpRecordTransBiz {



    @Override
    protected void transProcess0(DrpProcessCreateContext historyTransContext) {
        String createUser = historyTransContext.getProcessCreateContext().getProcessInstanceModel().getCreateUser();
        String bindId = historyTransContext.getProcessCreateContext().getProcessInstanceModel().getId();
        Timestamp startTime = historyTransContext.getProcessCreateContext().getProcessInstanceModel().getStartTime();
        List<BOCreateData> boCreateDataList = new ArrayList<>();
        RowMap mainData = historyTransContext.getMainData();
        SDK.getLogAPI().consoleInfo("获取班组数据");

        //添加日志
        String mainBOId = UUIDGener.getUUID();
        HistoryTransLogModel logModel = new HistoryTransLogModel();
        historyTransContext.setHistoryTransLogModel(logModel);
        logModel.setBindId(bindId);
        logModel.setBpmBOId(mainBOId);
        logModel.setBpmTable("BO_EU_MDM_CLASS");//项目基础信息
        logModel.setOuterTable("ct_laborteam");//基础项目信息表
        logModel.setOuterPK(mainData.getString("MyId"));
        logModel.setOuterExt1(mainData.getString("TeamLeader"));//班组长
        logModel.setOuterExt2(mainData.getString("BillNo"));//单据编号
        BOCreateData mainBOCreateData = new BOCreateData();
        boCreateDataList.add(mainBOCreateData);
        BO mainBO = new BO();
        mainBOCreateData.setBoName("BO_EU_MDM_CLASS");
        mainBOCreateData.setBo(mainBO);
        mainBOCreateData.setCreateUser(createUser);
        mainBO.setCreateDate(startTime);
        mainBO.setUpdateDate(startTime);
        mainBO.setId(mainBOId);

        mainBO.set("DATA_TYPE","2");//历史数据
        mainBO.set("DRP_ID",mainData.getString("MyId"));
        mainBO.set("APPLY_NO",mainData.getString("BillNo"));
        mainBO.set("APPLY_DATE",mainData.getString("CreateTime"));
        mainBO.set("APPLY_USER",mainData.getString("CreateName"));
        mainBO.set("APPLY_USER_ID",mainData.getString("CreateId"));
        mainBO.set("APPLY_DEPT",mainData.getString("CreateDept"));
        mainBO.set("APPLY_DEPT_ID",mainData.getString("CreateDeptId"));


        mainBO.set("ID_CARD",mainData.getString("IDCard"));
        mainBO.set("CLASS_LEAD_NAME",mainData.getString("TeamLeader"));
        mainBO.set("CLASS_LEAD_PHONE",mainData.getString("Phone"));
        mainBO.set("NATIVE_PLACE",mainData.getString("NativePlace"));

        mainBO.set("REPLACE_PAY_NO",mainData.getString("PayrollAccountNumber"));
        mainBO.set("IS_REAL_NAME",mainData.getString("WhetherRealName看看坎坎坷坷m"));
        mainBO.set("REGISTER_DATE",mainData.getString("RecordTime"));
        mainBO.set("REPLACE_PAY_BANK",mainData.getString("PayrollAccountBank"));
        mainBO.set("CLASS_GRADE",mainData.getString("TeamGrade"));
        mainBO.set("IS_BLACK",mainData.getString("BlacklistStatus"));
        mainBO.set("URGENT_CONTACT",mainData.getString("EmergencyContactpsn"));
        mainBO.set("RELATIONSHIP",mainData.getString("Relation"));
        mainBO.set("FUND_MIN",mainData.getString("CapitalCushionCapacity"));
        mainBO.set("FUND_MAX",mainData.getString("CapitalCushionCapacity"));
        mainBO.set("PROJECT_PRICE_MIN",mainData.getString("UndertakeProjectCostRange"));
        mainBO.set("PROJECT_PRICE_MAX",mainData.getString("UndertakeProjectCostRange"));
        mainBO.set("PAID_AMOUNT","");
        mainBO.set("URGENT_PHONE",mainData.getString("EmergencyContactpsnPhone"));
        mainBO.set("INTRO_COMPANY",mainData.getString("RecommendedUnit"));

        mainBO.set("INTRO_USER_NAME",mainData.getString("Referrer"));
        mainBO.set("SKILL_SAME",mainData.getString("ExcelOrSimilarProject"));
        mainBO.set("INTRO_PHONE",mainData.getString("ReferrerPhone"));
        mainBO.set("CLASS_LEAD_DUTY",mainData.getString("TeamWorkType"));
        //班组地址
        mainBO.set("CITY",mainData.getString("FamilyAddress"));
        mainBO.set("DETAIL_ADDRESS",mainData.getString("FamilyAddress"));
        mainBO.set("ADDRESS",mainData.getString("FamilyAddress"));
        mainBO.set("REMARK",mainData.getString("Memo"));

        String myId = mainData.getString("MyId");
        List<RowMap> contentData=SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMaps("select * from  ct_WorkerList where  MyParentId = '"+myId+"'");
        for(RowMap content:contentData){
            String uuid = UUIDGener.getUUID();
            BOCreateData subBOCreateData = new BOCreateData();
            boCreateDataList.add(subBOCreateData);
            subBOCreateData.setCreateUser(createUser);
            subBOCreateData.setBoName("BO_EU_MDM_CLASS_WORK_LIST");
            BO subBO = new BO();
            subBO.setId(uuid);
            subBOCreateData.setBo(subBO);
            subBO.set("CLASS",content.getString("WorkType"));//工种
            subBO.set("USER_NAME",content.getString("WorkerName"));
            subBO.set("TYPE", content.getString("PersonnelType"));
            subBO.set("ID_CARD", content.getString("IdCard"));
            super.addLogModel(historyTransContext, "ct_WorkerList", content.getString("MyId"), "BO_EU_MDM_CLASS_WORK_LIST", uuid, bindId);
        }
        historyTransContext.getProcessCreateContext().setBoCreateDatas(boCreateDataList);
    }

    @Override
    protected String getDrpType() {
        return null;
    }

    @Override
    protected String getOuterTable(DrpProcessCreateContext historyTransContext) {
        return "ct_laborteam";
    }

    @Override
    protected String getPk(DrpProcessCreateContext historyTransContext) {
        RowMap mainData = historyTransContext.getMainData();
        return mainData.getString("MyId");
    }
    @Override
    protected String getProcessDefId() {
        return "obj_d2ff75216f724b1d8e9cdbaa71483ab8";
    }

    @Override
    protected String getActivityDefId() {
        return null;
    }

    @Override
    protected String getTitle(HistoryTransContext ctx) {
        String billNo = ctx.getMainData().getString("BillNo");//单据号
        return "标书制作流程历史数据同步"+billNo;
    }

    @Override
    protected String getEnCode(HistoryTransContext ctx) {
        RowMap mainData = ctx.getMainData();
        return mainData.getString("Wiid");
    }




    @Override
    protected List<RowMap> getMainDatas() {
        return SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMaps("SELECT * FROM ct_laborteam limit 50 ");
    }

    @Override
    protected RowMap getMainData() {
        return null;
    }
}
